home *** CD-ROM | disk | FTP | other *** search
- /*
- File: SpinCursor.c
- By: Nitin Ganatra.
- Modifications by Rich Kubota
- */
-
- #include "SpinCursor.h" /* Get the prototypes for the application. */
-
- /* Some module-local globals */
- static short gTickInterval; // number of ticks between a frame switch */
- static long gTickDefer; // time to wait before spinning the cursor
- static long gLastTick; // tick count of last call to SpinCursor */
- static animatedCursorHandle gFrameList; // our cursor list */
-
- //----------------------------------------------------------------------------
- // InitAnimatedCursors
- //
- // Init the cursor information from the current resource file
- // acurID: 'acur' resource ID to use for the busy cursor
- //
- //----------------------------------------------------------------------------
-
- Boolean InitAnimatedCursors(short acurID)
- {
- register short i=0;
- register short cursID;
- Boolean noErrFlag = false;
-
- gFrameList = (animatedCursorHandle)GetResource('acur',acurID);
- if (gFrameList != NULL) {
-
- /* got it! */
- noErrFlag = true;
- while((i<(*gFrameList)->numberOfFrames) && noErrFlag) {
-
- /* The id of the cursor is stored in the high word of the frame handle */
- cursID = (short) HiWrd((long) (*gFrameList)->frame[i]);
- (*gFrameList)->frame[i] = GetCursor(cursID);
- if((*gFrameList)->frame[i])
- i++; /* get the next one */
- else
- noErrFlag=false; /* foo! we couldn't find the cursor */
- }
- }
- // set cursor to no spin
- gTickDefer = kDontSpinCursor;
- return noErrFlag;
- }
-
- //----------------------------------------------------------------------------
- // StartAnimatedCursors - inits the interval and deferral period for spinning the cursor
- //
- // interval: the interval that must pass from spinning the cursor last, which
- // must pass before spinning the cursor again.
- // deferral: number of ticks after the InitAnimatedCursors call is made that
- // spinning will occur. If the gTickDefer is -1
- // then the cursor will never spin
- //
- //----------------------------------------------------------------------------
- void StartAnimatedCursors(short interval, short deferral)
- {
- /* We have the cursors, now initialize the other fields */
- gTickInterval = interval;
- gLastTick = TickCount();
- gTickDefer = deferral + gLastTick;
- (*gFrameList)->whichFrame = 0;
- }
-
- void StopAnimatedCursors(void)
- {
- gTickDefer = kDontSpinCursor;
- }
-
- //----------------------------------------------------------------------------
- // ReleaseAnimatedCursors
- //----------------------------------------------------------------------------
- void ReleaseAnimatedCursors(void)
- {
- short i;
-
- gTickDefer = kDontSpinCursor; // make sure that we can't spin the cursor
- for(i = 0; i < (*gFrameList)->numberOfFrames; i++)
- ReleaseResource((Handle) (*gFrameList)->frame[i]);
- ReleaseResource((Handle) gFrameList);
-
- }
-
-
- //----------------------------------------------------------------------------
- // SpinTheCursor
- //
- // Just call this whenever you need to increment the spinning cursor.
- // A typical sequence would look like this:
- //
- // InitAnimatedCursor(1002);
- // StartAnimatedCursors(6, 30);
- // for (x = 1; x < kMaxSomething; x ++) {
- // SpinTheCursor();
- // DoTimeConsumingThing();
- // }
- // StopAnimatedCursors();
- // ReleaseAnimatedCursors();
- //----------------------------------------------------------------------------
- void SpinTheCursor(void)
- {
- register long newTick;
-
- // check gTickInterval
- if (gTickDefer == kDontSpinCursor)
- return;
-
- // we're spinning, so check the current time
- newTick = TickCount();
-
- // have we passed the deferral period
- if (newTick < (unsigned long)gTickDefer)
- return; // nope
-
- /* Is it time? */
- if(newTick < (gLastTick + gTickInterval))
- return; /* nope */
-
- /* Grab the frame, increment (and reset, if necessary) the count, and
- display the new cursor */
- SetCursor(*((*gFrameList)->frame[(*gFrameList)->whichFrame++]));
- if((*gFrameList)->whichFrame == (*gFrameList)->numberOfFrames)
- (*gFrameList)->whichFrame = 0;
- gLastTick = newTick;
- }
-